from pydantic import BaseModel
from typing import List
from datetime import datetime

# 社区的流量统计模型
class CommunityFlowStats(BaseModel):
    community_id: int
    borrow_count: int
    return_count: int
    net_flow: int

class FlowStatsData(BaseModel):
    start_slot: str
    end_slot: str
    stats: List[CommunityFlowStats]

class FlowStatsResponse(BaseModel):
    code: int
    message: str
    data: FlowStatsData

# OD 对的流量统计模型
class ODPair(BaseModel):
    start_community_id: int
    end_community_id: int
    flow_count: int

class ODData(BaseModel):
    start_slot: str
    end_slot: str
    od_pairs: List[ODPair]

class ODResponse(BaseModel):
    code: int
    message: str
    data: ODData


# 单社区历史24h时间序列数据模型
class TimeSeriesPoint(BaseModel):
    time_slot: datetime
    borrow_count: int
    return_count: int

class TimeSeriesData(BaseModel):
    community_id: int
    start_time: datetime
    end_time: datetime
    series: List[TimeSeriesPoint]

class TimeSeriesResponse(BaseModel):
    code: int
    message: str
    data: TimeSeriesData


# 定义单个历史数据点的格式
class HistoricalFlowPoint(BaseModel):
    community_id: int
    time_slot: datetime
    net_flow: int

# 定义新接口的完整响应体
class AllHistoricalFlowsResponse(BaseModel):
    code: int
    message: str
    data: List[HistoricalFlowPoint]